package com.ziytek.web.citizen.controller;

import com.google.gson.Gson;
import com.ziytek.web.citizen.constant.ApiConstant;
import com.ziytek.web.citizen.model.req.BatteryComprehensiveExportReq;
import com.ziytek.web.citizen.model.req.BatteryExportReq;
import com.ziytek.web.citizen.model.req.CapDetailQueryReq;
import com.ziytek.web.citizen.model.req.CapStatusQueryReq;
import com.ziytek.web.citizen.service.CapacityDetailExportService;
import com.ziytek.web.citizen.service.CapacityStatusExportService;
import com.ziytek.web.citizen.service.itf.BatteryExportService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;


/**
 * 数据导出
 *
 * @className ExportDataController
 * @description: 数据导出
 * @jdkVersion: 1.8
 * @author: fhx
 * @date: 2024/7/2 9:53
 */
@Slf4j
@RestController
@RequestMapping(ApiConstant.API_CABINET)
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ExportDataController {
    private final Gson gson;
    private final BatteryExportService exportService;
    private final CapacityStatusExportService capacityStatusExportService;
    private final CapacityDetailExportService capacityDetailExportService;

    /**
     * 电池充放电详情数据导出接口
     *
     * @param request      导出请求参数
     * @param httpResponse 导出响应
     */
    @PostMapping(ApiConstant.BATTERY_DETAILS_EXPORT)
    public void batteryDetailsExport(HttpServletResponse httpResponse, @RequestBody BatteryExportReq request) {
        log.info("batteryDetailsExport start:{}", request);
        exportService.batteryExportZip(request, httpResponse);
    }

    /**
     * 电池综合列表数据导出接口
     *
     * @param request      导出请求参数
     * @param httpResponse 导出响应
     */
    @PostMapping(ApiConstant.BATTERY_COMPREHENSIVE_EXPORT)
    public void batteryComprehensiveExport(HttpServletResponse httpResponse, @RequestBody BatteryComprehensiveExportReq request) {
        log.info("batteryComprehensiveExport start:{}", request);
        exportService.batteryComprehensiveExport(request, httpResponse);
    }

    /**
     * 电池容量详情数据导出接口
     *
     * @param request 请求参数
     */
    @PostMapping(ApiConstant.CAPACITY_DETAIL_EXPORT)
    public void capDetailExport(@Valid @RequestBody CapDetailQueryReq request, HttpServletResponse response) throws IOException {
        log.info("capDetailExport:{}", gson.toJson(request));
        capacityDetailExportService.capDetailExport(request, response);
    }

    /**
     * 电池放电容量数据导出接口
     *
     * @param request 请求参数
     */
    @PostMapping(ApiConstant.CAPACITY_STATUS_EXPORT)
    public void capacityStatusExport(@Valid @RequestBody CapStatusQueryReq request, HttpServletResponse response) throws IOException {
        log.info("capacityStatusExport:{}", gson.toJson(request));
        capacityStatusExportService.export(request, response);
    }
}

